<?php
    // RECEIVES THE ATTACHMENT FROM THE INCOMING DOCUMENT ON THE DASHBOARD
    // Created By : Noan Babao
    // B.S. Computer Science - De La Salle Canlubang
    // Nov 11,2011
    //NOT IN parameters : l
    //NOT OUT parameters : List of Attachments.

// Start - Checker for those users who will just go to the page by typing directly in the url.
if ($_POST) {   
    // INCLUDES CONFIGURATION VARIABLES FOR DATABASE ACCESS
 $hostName = "localhost";
 $rootName = "dbasegr";
 $dBasePassword = "dbgr2012";
 $dBaseName = 'greenroute';

//    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');

// GET VARIABLES VIA POST METHOD
    
$docId = $_POST['documentId'];
$location =  $_POST['location'];

date_default_timezone_set('Asia/Singapore');
$currentDateTime= date("Y-m-d H:i:s" , time());

  $query = 
        "
            UPDATE Attachment
            SET location = '$location'
            WHERE attachmentId = '$docId'
        ";
    mysql_query($query);
 

    
     $queryLog = 
            "
                INSERT into Log (documentId, userId, stepId, logDateTime, activity)
                values('$docId' , '$location' , NULL , '$currentDateTime' , 'Received');
            ";
    mysql_query($queryLog);

    
    
     $querySent_Attachment = 
            "
                UPDATE Sent_Attachment
                SET receiveFlag = 'Received'
                WHERE documentId = '$docId'
            ";
    mysql_query($querySent_Attachment);
    echo json_encode(1);

 mysql_close($connect);
}   // End - Checker for those users who will just go to the page by typing directly in the url.
else {
 echo "You are not authorized to view this page. This incident will be reported immediately.";
} 
?>
